import java.util.*;

/**
 * 用户类，用于表示用户信息
 */
class User {
    private String username;
    private String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

/**
 * 测试类，实现登录功能
 */
public class LoginTest {
    public static void main(String[] args) {
        // 创建集合存储用户对象
        List<User> users = new ArrayList<>();

        // 添加5个用户对象
        users.add(new User("admin", "123456"));
        users.add(new User("user1", "password1"));
        users.add(new User("user2", "password2"));
        users.add(new User("user3", "password3"));
        users.add(new User("user4", "password4"));

        Scanner scanner = new Scanner(System.in);
        int attempts = 3; // 登录尝试次数

        System.out.println("=== 用户登录系统 ===");

        while (attempts > 0) {
            System.out.print("请输入用户名: ");
            String inputUsername = scanner.nextLine();

            System.out.print("请输入密码: ");
            String inputPassword = scanner.nextLine();

            // 验证用户信息
            boolean loginSuccess = false;
            for (User user : users) {
                if (user.getUsername().equals(inputUsername) && user.getPassword().equals(inputPassword)) {
                    loginSuccess = true;
                    break;
                }
            }

            if (loginSuccess) {
                System.out.println("登录成功！");
                break;
            } else {
                attempts--;
                System.out.println("登录失败！剩余尝试次数: " + attempts);

                if (attempts == 0) {
                    System.out.println("登录失败次数过多，账户已被锁定。");
                }
            }
        }

        scanner.close();
    }
}
